package com.wxy.demo.thread;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 线程停止
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2022/10/11 14:42
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            try {
                try {
                    TimeUnit.SECONDS.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("子线程执行完成");
            } finally {
                System.out.println("执行finally代码");
            }
        });
        thread.start();
        TimeUnit.SECONDS.sleep(1);
        thread.stop();
        System.out.println("子线程停止成功");
    }
}
